package com.example.util;


import java.security.MessageDigest;

import org.springframework.stereotype.Component;

/**
 * 使用md5的方式对password进行加密
 * @author lenovn
 *
 */
//@Component
public class Md5util {

	public final static String Md5(String password){
		char[] md5String={'1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F'};
		byte[] byteInput= password.getBytes();
		try{
		   MessageDigest mdInst= MessageDigest.getInstance("MD5");
		   mdInst.update(byteInput);
		   byte[] md=mdInst.digest();
		   int j= md.length;
		   char[] str= new char[j*2];
		   int k=0;
		   for(int i=0;i<j;i++){
			   byte byte0=md[i];
			   str[k++]= md5String[byte0>>>4 & 0xf];
			   str[k++]= md5String[byte0 & 0xf];
		   }
		   
		   return new String(str);
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
	
}
